<?php

class NHelperImage {


static function  resize($filename,$resize_form="50x",$newfilename=''){
   NHelperImage::resize_gd($filename,$resize_form,$newfilename);
}
static function resize_im($filename,$resize_form="50x",$newfilename=''){
if (!$newfilename) $newfilename=$filename;
$command="convert -resize '$resize_form' $filename  $newfilename ";
//echo $command."\n";
echo system($command);
}

static function resize_gd($filename,$resize_form="50x",$newfilename=''){
if (!$newfilename) $newfilename=$filename;
$aArrExt = split('\.',$filename);
$ext=$aArrExt[count($aArrExt)-1];

$image_details = getimagesize($filename);
$width = $image_details[0];
$height = $image_details[1];

$aGeometry=preg_split('/x/',$resize_form);
if ($aGeometry[0]) $res_width=$aGeometry[0];
if ($aGeometry[1]) $res_width=$aGeometry[1];
$percent = $percentage = ($res_width / $width); 
$res_height = $percent*$height;

$dest = imagecreatetruecolor($res_width, $res_height);

//echo $ext;
 switch ($image_details['mime']){
	case'image/jpeg':
	$source = imagecreatefromjpeg($filename);
	imagecopyresampled ($dest, $source, 0, 0, 0, 0, $res_width, $res_height, $width, $height);
	imagejpeg($dest,$newfilename , 90);
	break;
	case'image/gif':
	$source = imagecreatefromgif($filename);
	imagecopyresampled ($dest, $source, 0, 0, 0, 0, $res_width, $res_height, $width, $height);
	imagejpeg($dest,$newfilename , 90);
	break;

	
	
}






imagedestroy($dest);
imagedestroy($source);


}



}
?>